<?php

include dirname(dirname(__FILE__)) . '/include/common.php';

class webServiceGetAdvertisement extends core {

    public function process() {
         $data_ads = $this->db->get_results("SELECT * FROM advertisements WHERE `active`='1' ORDER BY sorting_order ASC");
         if ($data_ads ) {
            $html='<ul>';
           foreach($data_ads as $ad){
               $html.='<li><a href="#" onclick="var ref = window.open(\''.$ad->url.'\', \'_system\');"  title="'.$ad->image_file.' "><img src="'.$this->GetAbsoluteURLFolder().'/ads_photos/'.$ad->image_file.'" border="0" alt="'.$ad->image_file.' "></a></li>';
           }
           $html.='</ul>';
            $this->_JSONResponse(array('error' => 0, 'html' => $html ));
        } else {
            $this->_JSONResponse(array('error' => 1,'msg'=>'User does not exist'));
        }
    }
    function GetAbsoluteURLFolder() {
        $scriptFolder = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://';
        $scriptFolder .= $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
        return $scriptFolder;
    }

}

$processor = new webServiceGetAdvertisement();
$processor->process();
?>